class EventSource(object):
    
    def __init__(self):
        self.handlers = {};
        
    def connect(self,event,handler,*handlerParams):
        l = self.handlers.get(event);
        if l == None:
            self.handlers[event] = l = [];
        l.append((handler,handlerParams));
        
    def emit(self,event,*eventParams):
        l = self.handlers.get(event);
        if l == None:
            return None;
        for (handler,handlerParams) in l:
            if len(handlerParams) == 0:
                handler(self,*eventParams);
            else:
                params = [];
                params.extend(eventParams);
                params.extend(handlerParams);
                handler(self,*params);
                
    def disconnect(self,handler,*handlerParams):
        try:
            l.remove((handler,handlerParams));
        except ValueError:
            pass;


        